﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace FoodWar.Episode1.Components.Particles.ParticleSystems
{
    public class Torch : ParticleSystem
    {
        public Vector3 Position;
        public GameFITClub game;

        public Torch(Game game, Vector3 position)
            : base(game, game.Content)
        {
            this.Position = position;
            this.game = (GameFITClub)game;
        }

        protected override void InitializeSettings(ParticleSettings settings)
        {
            settings.TexturePath = "Sprites\\fire";
            settings.EffectPath = "Shaders\\ParticleEffect";

            settings.MaxParticles = 90;

            settings.Duration = TimeSpan.FromSeconds(1.5);

            settings.DurationRandomness = 1;

            settings.MinHorizontalVelocity = 0.00f;
            settings.MaxHorizontalVelocity = 0.075f;

            settings.MinVerticalVelocity = -0.05f;
            settings.MaxVerticalVelocity = 0.05f;

            // Set gravity upside down, so the flames will 'fall' upward.
            settings.Gravity = new Vector3(0, 0.1f, 0);

            settings.MinColor = new Color(255, 100, 20, 10);
            settings.MaxColor = new Color(255, 200, 20, 40);

            settings.MinStartSize = 0.10f;
            settings.MaxStartSize = 0.20f;

            settings.MinEndSize = 0.05f;
            settings.MaxEndSize = 0.10f;

            // Use additive blending.
            settings.BlendState = BlendState.AlphaBlend;
        }

        public override void Update(GameTime gameTime)
        {
            const int fireParticlesPerFrame = 1;

            for (int i = 0; i < fireParticlesPerFrame; i++)
            {
                this.AddParticle(this.Position, Vector3.Zero);
            }
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            this.SetCamera(this.game.ViewMatrix, this.game.ProjectionMatrix);
            base.Draw(gameTime);
        }
    }
}
